//
//  BSMainInterfaceView.m
//  SuoSiApp
//
//  Created by zhang on 16/4/6.
//  Copyright © 2016年 Ym. All rights reserved.
//

#import "BSMainInterfaceView.h"

@implementation BSMainInterfaceView
- (instancetype)initWithFrame:(CGRect)frame{

    self = [super initWithFrame:frame];
    if (self) {
     [self addSubview]   ;
    }
    return self;
}

- (void)addSubview{

    self.backgroundImageview = [[UIImageView alloc]initWithFrame:self.bounds];
    self.backgroundImageview.userInteractionEnabled = YES;
    self.backgroundImageview.image = [UIImage imageNamed:@"main_bg.jpg"];
    [self addSubview:_backgroundImageview];
    
    self.kindsImageview = [[UIImageView alloc]initWithFrame:CGRectMake(kScrenWidth/4, kScrenHeight * 1 / 3, kScrenWidth/2, kScrenWidth/2)];
    self.kindsImageview.userInteractionEnabled = YES;
    self.kindsImageview.image = [UIImage imageNamed:@"main_modebg.png"];
    
//    用户界面 用户名字
    self.userLable = [[UILabel alloc]initWithFrame:CGRectMake(0, kScrenHeight/4 - kMartin20, kScrenWidth, kMartin30)];
    self.userLable.textColor = BSWhite;
    
    NSMutableAttributedString *str;
    if ([BSUserSGton userHandle].realName && [BSUserSGton userHandle].realName.length > 1) {
        str =[[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"欢迎您登陆, %@",[BSUserSGton userHandle].realName]];
    } else {
        str =[[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"欢迎您登陆, %@",[BSUserSGton userHandle].user_loginName]];
    }
    
//    [str addAttribute:NSForegroundColorAttributeName value:BSBTGreen range:NSMakeRange(str.length - 3,3)];
    self.userLable.attributedText = str;
    self.userLable.textAlignment = NSTextAlignmentCenter;
    [self.backgroundImageview addSubview:_userLable];
 
    
    
//    佩戴模式
    CGRect frame1 = CGRectMake(- self.kindsImageview.left / 3 , - ( self.kindsImageview.left / 3 ), kScrenWidth/4, kScrenWidth/4);
    
   self.adornModeBT = [self makeButton:frame1 :@"佩戴\n模式" :@"main_nor_select.png"];
    [self.backgroundImageview addSubview:_kindsImageview];


    
    
    
//    家属模式
    CGRect frame2 = CGRectMake( self.kindsImageview.width * 2 / 3 , - ( self.kindsImageview.left / 3 ), kScrenWidth/4, kScrenWidth/4);
    
    
    self.familyModeBT = [self makeButton:frame2 :@"家属\n模式" :@"main_nor_select.png"];
//    运动模式
    CGRect frame3 = CGRectMake(- self.kindsImageview.left / 3 , ( self.kindsImageview.width * 2 / 3 ), kScrenWidth/4, kScrenWidth/4);
    

    
    self.sportModeBT = [self makeButton:frame3 :@"运动\n模式" :@"main_nor_select.png"];

    
//    监护模式
    
    CGRect frame4 = CGRectMake(self.kindsImageview.width * 2 / 3, self.kindsImageview.width * 2 / 3, kScrenWidth/4, kScrenWidth/4);
    self.ICUModeBT = [self makeButton:frame4 :@"监护\n模式" :@"main_nor_select.png"];
    
//    退出按钮
    self.exitBTL = BSButton;
    self.exitBTL.frame = CGRectMake(kMartin30,kScrenHeight - kMartin50, kMartin30, kMartin30);
    [self.exitBTL setBackgroundImage:[UIImage imageNamed:@"main_logout_sel.png"] forState:(UIControlStateNormal)];
    [self.backgroundImageview addSubview:self.exitBTL];
    
    self.exitBTR = BSButton;
    self.exitBTR.frame = CGRectMake(self.exitBTL.right + kMartin5, self.exitBTL.top, kMartin80, kMartin30);
    [self.exitBTR setTitle:@"退出登录" forState:(UIControlStateNormal)];
    [self.exitBTR setTitleColor:BSBlack forState:(UIControlStateNormal)];    [self.backgroundImageview addSubview:_exitBTR];
    
//    设置
    self.settingBTL = BSButton;
    self.settingBTL.frame = CGRectMake(kScrenWidth - kMartin100, self.exitBTL.top, kMartin30, kMartin30) ;
    [self.settingBTL setBackgroundImage:[UIImage imageNamed:@"main_settings_sel.png"] forState:(UIControlStateNormal)];
    [self.backgroundImageview addSubview:_settingBTL];
    
    self.settingBTR = BSButton;
    self.settingBTR.frame = CGRectMake(self.settingBTL.right + kMartin5, self.settingBTL.top, kMartin50, kMartin30);
    [self.settingBTR setTitle:@"设置" forState:(UIControlStateNormal)];
    [self.settingBTR setTitleColor:BSBlack forState:(UIControlStateNormal)];
    [self.backgroundImageview addSubview:_settingBTR];
    
    
    

}


- (UIButton *)makeButton:(CGRect)frame :(NSString *)title :(NSString *)imageName {

    UIButton *button = BSButton;
    button.frame  = frame;
//    button.backgroundColor = BSRed;
    UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(button.width/10, button.width/10, button.width * 2/3, button.width * 2/3)];
    lable.numberOfLines = -1;
   // lable.backgroundColor = BSGreen;
    lable.textAlignment = NSTextAlignmentCenter;
    lable.font = [UIFont systemFontOfSize:18];
    lable.text = title;
    [button addSubview:lable];
    
    [button setBackgroundImage:[UIImage imageNamed:imageName] forState:(UIControlStateNormal)];
    [self.kindsImageview addSubview:button];

    return button;
}



@end
